#ifndef YCONFIGCOMPONENT_H
#define YCONFIGCOMPONENT_H

#include "Defines.h"
#include "OString.h"

namespace Y{

class ConfigComponent{

public:
	template <class C>
	ConfigComponent( const OString& str, C v ):
		name(str),
		type( -1 )
	{
		C *p = reinterpret_cast<C*> ( &value[0] );
		*p = v;
	}
	
	
	
	
	ConfigComponent( const OString& str, int v ):
		name(str),
		type( O_int )
	{
		int *p = reinterpret_cast<int*> ( &value[0] );
		*p = v;
	}	
	ConfigComponent( const OString& str, float v ):
		name(str),
		type( O_float )
	{
		float *p = reinterpret_cast<float*> ( &value[0] );
		*p = v;
	}	
	ConfigComponent( const OString& str, int i, bool b ):
		name(str)
	{
		Vertex2i v(i,(int) b);
		Vertex2i *p = reinterpret_cast<Vertex2i*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, double d0 ):
		name(str),
		type( O_float )
	{
		float *p = reinterpret_cast<float *> (&value[0]);
		*p = (float) d0;
	}
	
	ConfigComponent( const OString& str, float f0, float f1 ):
		name(str)
	{
		Vertex2f v(f0,f1);
		Vertex2f *p = reinterpret_cast<Vertex2f*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, double f0, float f1 ):
		name(str)
	{
		Vertex2f v(f0,f1);
		Vertex2f *p = reinterpret_cast<Vertex2f*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, float f0, double f1 ):
		name(str)
	{
		Vertex2f v(f0,f1);
		Vertex2f *p = reinterpret_cast<Vertex2f*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, double f0, double f1 ):
		name(str)
	{
		Vertex2f v(f0,f1);
		Vertex2f *p = reinterpret_cast<Vertex2f*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, float f0, float f1, float f2 ):
		name(str)
	{
		Vertex3f v(f0,f1,f2);
		Vertex3f *p = reinterpret_cast<Vertex3f*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, float f0, double f1, double f2 ):
		name(str)
	{
		Vertex3f v(f0,f1,f2);
		Vertex3f *p = reinterpret_cast<Vertex3f*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, double f0, float f1, float f2 ):
		name(str)
	{
		Vertex3f v(f0,f1,f2);
		Vertex3f *p = reinterpret_cast<Vertex3f*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, double f0, double f1, float f2 ):
		name(str)
	{
		Vertex3f v(f0,f1,f2);
		Vertex3f *p = reinterpret_cast<Vertex3f*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, float f0, double f1, float f2 ):
		name(str)
	{
		Vertex3f v(f0,f1,f2);
		Vertex3f *p = reinterpret_cast<Vertex3f*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, float f0, float f1, double f2 ):
		name(str)
	{
		Vertex3f v(f0,f1,f2);
		Vertex3f *p = reinterpret_cast<Vertex3f*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, double f0, double f1, double f2 ):
		name(str)
	{
		Vertex3f v(f0,f1,f2);
		Vertex3f *p = reinterpret_cast<Vertex3f*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, float f0, float f1, float f2, float f3 ):
		name(str)
	{
		Vertex4f v(f0,f1,f2,f3);
		Vertex4f *p = reinterpret_cast<Vertex4f*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, double f0, float f1, float f2, float f3 ):
		name(str)
	{
		Vertex4f v(f0,f1,f2,f3);
		Vertex4f *p = reinterpret_cast<Vertex4f*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, double f0, double f1, float f2, float f3 ):
		name(str)
	{
		Vertex4f v(f0,f1,f2,f3);
		Vertex4f *p = reinterpret_cast<Vertex4f*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, double f0, double f1, double f2, float f3 ):
		name(str)
	{
		Vertex4f v(f0,f1,f2,f3);
		Vertex4f *p = reinterpret_cast<Vertex4f*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, double f0, float f1, double f2, float f3 ):
		name(str)
	{
		Vertex4f v(f0,f1,f2,f3);
		Vertex4f *p = reinterpret_cast<Vertex4f*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, double f0, float f1, double f2, double f3 ):
		name(str)
	{
		Vertex4f v(f0,f1,f2,f3);
		Vertex4f *p = reinterpret_cast<Vertex4f*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, float f0, double f1, double f2, double f3 ):
		name(str)
	{
		Vertex4f v(f0,f1,f2,f3);
		Vertex4f *p = reinterpret_cast<Vertex4f*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, float f0, float f1, double f2, double f3 ):
		name(str)
	{
		Vertex4f v(f0,f1,f2,f3);
		Vertex4f *p = reinterpret_cast<Vertex4f*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, float f0, double f1, float f2, float f3 ):
		name(str)
	{
		Vertex4f v(f0,f1,f2,f3);
		Vertex4f *p = reinterpret_cast<Vertex4f*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, double f0, double f1, double f2, double f3 ):
		name(str)
	{
		Vertex4f v(f0,f1,f2,f3);
		Vertex4f *p = reinterpret_cast<Vertex4f*> ( &value[0] );
		*p = v;
	}
	
	ConfigComponent( const OString& str, const char *c ):
		name(str),
		type(O_string)
	{
//		if ( strlen(c) > 1000 ){ exit(139); }
//		strcpy(value,c);
		const char * *p = reinterpret_cast<const char * *> ( &value[0] );
		*p = c;
	}
	
	ConfigComponent( const OString& str, const char *c0, const char *c1, const char *c2 = NULL, const char *c3 = NULL ):
		name(str),
		type(O_string)
	{
		Vertex< 4, const char * > v(c0,c1,c2,c3);
		Vertex< 4, const char * > * p = reinterpret_cast<Vertex< 4, const char * >*> ( &value[0] );
		*p = v;
	}
	
	char value[100];
	OString name;
	int type;
	
	template <class C>
	inline C& cast (){
		return * ((C*) ( &value[0] ));
	}
	
	template <class C>
	inline C& to (){
		return * ((C*) ( &value[0] ));
	}
	
	inline OString& toString (){
		return (* (* ((OString**) ( &value[0] ))));
	}
	
	template <class C>
	inline void castInto (C& v){
		C *p = reinterpret_cast<C*> ( &value[0] );
		v = *p;
	}
	
	
	bool operator== (const char *c){ return (name == c); }

};

}
#endif
